﻿using Server.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using Server.CustomObjects;

namespace Server.DataBase
{
    class DBMain : IDataBase
    {
        public DBContacts Contacts { get { return this.mContacts; } }
        public DBSession Session { get { return this.mSession; } }
        public DBUser User { get { return this.mUser; } }
        #region Database Properties
        public String Password { get; set; }
        public String Username { get; set; }
        public String Database { get; set; }
        public String ServerURL { get; set; }
        public bool TrustedConnection { get; set; }
        #endregion
        public int Timeout { get; set; }
        MySqlConnection mConnection;
        DBContacts mContacts;
        DBUser mUser;
        DBSession mSession;

        public DBMain()
        {
            //TODO: Sollen die Werte aus den Projektprops bekommen.
            this.Username = "test";
            this.Password = "test123";
            this.ServerURL = "46.163.109.112";
            this.Timeout = 1000;
            this.Database = "TestDB";

            //connectionString = "Server=" + this.ServerURL + ";" + "Database=" +
            //this.Database + ";" + "Uid=" + this.Username + ";" + "Pwd=" + this.Password + ";";

            string connStr = "server=" + Globals.Network.ServerIp 
                            +";user id=" + Globals.Security.MySql_UserName 
                            +";database=" + Globals.Security.MySql_Schema
                            +";port=" + Globals.Security.MySql_Port
                            +";password=" + Globals.Security.MySql_Password;

            mConnection = new MySqlConnection(connStr);
            mConnection.Open();

            this.mContacts = new DBContacts(mConnection);
            this.mSession = new DBSession(mConnection);
            this.mUser = new DBUser(mConnection);
            Globals.checkDataBase(mConnection);
            this.test();
        }

        private void test()
        {
        }
    }
}

